import "dotenv/config";
import got from "got";
import cheerio from 'cheerio';
import { readFileByType, writeFileByType } from "./util";

const zentaosid = readFileByType('zentao_cookie');
const getZentao = async () => {
    const url = "http://115.233.227.46:2233/zentao/project-bug-52-status,id_desc-0-bySearch-myQueryID.html";
    const headers = {
        Cookie: `zentaosid=${zentaosid}`,
    }
    const { body } = await got.get(url, {
        method: "GET",
        headers
    });
    const $ = cheerio.load(body);
    const list: any[] = [];
    $("#bugList > tbody > tr > td:nth-child(4)").each((i, m) => {
        list.push({ id: i, title: m.attribs.title });
    });
    writeFileByType(`zentao.task.list`, list, 'json');
    return list;
}
export { getZentao };